import request from '@/api/request';
// 在非组件模块中获取 store必须通过这种方式
// 这里单独加载store，和在组件中this.$store一个东西
import store from '@/store/'

// 登录/注册
export const loginApi = (data) => {
  return request({
    method: 'POST',
    url: '/app/v1_0/authorizations',
    data
  });
}

// 发送短信验证码
export const sendSmsApi = mobile => {
  return request({
    method: "GET",
    url: `/app/v1_0/sms/codes/${mobile}`
  })
}

// 获取登录用户信息
export const userInfoApi = () => {
  return request({
    method: "GET",
    url: "/app/v1_0/user",
    // headers: {'Authorization': `Bearer ${store.state.user.token}`},
  })
}

// 关注用户
export const followUserApi = (target) => {
  return request({
    method: "POST",
    url: "/app/v1_0/user/followings",
    data: {
      "target": target
    }
  })
}

// 取消关注用户
export const cancelFollowUserApi = (target) => {
  return request({
    method: "DELETE",
    url: `/app/v1_0/user/followings/${target}`
  })
}

// 获取用户个人资料
export const getUserProfile = () => {
  return request({
    method: "GET",
    url: "/app/v1_0/user/profile"
  })
}

// 编辑用户个人资料（包含实名认证）
export const updateUserInfo = (data) => {
  return request({
    method: "PATCH",
    url: "/app/v1_0/user/profile",
    data
  })
}

// 编辑用户照片资料（头像、身份证照片）
export const updateUserPhoto = data => {
  return request({
    method: "PATCH",
    url: "/app/v1_0/user/photo",
    data
  })
}